/*
 * ViewLevel.cpp
 *
 *  Created on: 22/05/2014
 *      Author: lucio
 */

#include "ViewLevel.h"
#include "ViewConstant.h"
#include "ViewUtils.h"

bool ViewLevel::Init(){
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1) {
        return false;
    }

    this->screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);

    if(this->screen == NULL) {
        return false;
    }

    SDL_WM_SetCaption("Bomberman vs Zombies vs Plants", NULL);

    return true;
}

bool ViewLevel::LoadBackground() {
    this->background = Utils::LoadImage("bg.png");

    if(this->background == NULL) {
        return false;
    }
    return true;
}

void ViewLevel::CleanUp() {
    SDL_FreeSurface(this->background);
    SDL_Quit();
}

int ViewLevel::Execute(){
	    //bool quit = false;
	    //The frame rate regulator
	    //Timer fps;

	    //Initialize
	    if(this->Init() == false) {
	        return 1;
	    }
	    //Load the files
	    if(this->LoadBackground() == false) {
	        return 1;
	    }

		Utils::ApplySurface(0, 0, this->background, this->screen, &this->camera);

		SDL_Flip(this->screen);

		SDL_Delay(5000);

	    //Clean up
	    this->CleanUp();

	    return 0;
}

ViewLevel::ViewLevel(const std::string& genericPath) {
	this->screen = NULL;
	this->background = NULL;
	this->camera.x = 0;
	this->camera.y = 0;
	this->camera.w = SCREEN_WIDTH;
	this->camera.h = SCREEN_HEIGHT;
	this->genericPath = genericPath;
}

ViewLevel::ViewLevel() { }

ViewLevel::~ViewLevel() { }

